package com.wangzhixuan.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wangzhixuan.commons.utils.PageInfo;
import com.wangzhixuan.model.Meeting;
import com.wangzhixuan.model.Recordings;
import com.wangzhixuan.mapper.MeetingMapper;
import com.wangzhixuan.mapper.RecordingsMapper;
import com.wangzhixuan.mapper.VisitRecordingsMapper;
import com.wangzhixuan.service.IRecordingsService;
import com.baomidou.mybatisplus.plugins.Page;

import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhixuan.wang
 * @since 2017-08-13
 */
@Service
public class RecordingsServiceImpl extends ServiceImpl<RecordingsMapper, Recordings> implements IRecordingsService {
	
	@Autowired
    private RecordingsMapper recordingsMapper;
    
	@Autowired
    private MeetingMapper meetingMapper;
	
	@Autowired
    private VisitRecordingsMapper visitRecordingsMapper;
	
	@Override
    public void selectDataGrid(PageInfo pageInfo) {
    	Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageInfo.getNowpage(), pageInfo.getSize());
        page.setOrderByField(pageInfo.getSort());
        page.setAsc(pageInfo.getOrder().equalsIgnoreCase("asc"));
        List<Recordings> list = recordingsMapper.selectRecordingsPage(page, pageInfo.getCondition());
        pageInfo.setRows(list);
        pageInfo.setTotal(page.getTotal());
    }
	
	
	
	
	//目前通过WORDID来判断这个工作是否创建会议 就算是不同 的User进来，只要在同一个工作中wordId相同，有一个人创建了会议，会议状态是共享在wordId里所有人的
	//因为目前所有人都只能看到相关自己的工作，所以不需要通过job_people_word来判断这个人是否在这个任务中，只要看到了就一定是自己参与的在工作
	//如果日后要改可以查看全部人的信息，点击进来的时候就需要判断这个人是否参与了这个工作，如果wordId一对多的关系中没有个这个userId,则没有创建会议的权限，也无法查看他人的会议
	@Override
	public Map<String,Object> selectRecordings(Integer userId, Integer workId,
			String meeting) {
		Map<String,Object> paramMap = new HashMap<String,Object>();
		Map<String,Object> resultMap = new HashMap<String,Object>();
		paramMap.put("userId", userId);
		paramMap.put("workId", workId);
		paramMap.put("meeting", meeting);
		String status = meetingMapper.selectStatus(paramMap);		//通过meeting，以及workId来判断
		Meeting meeting2 = meetingMapper.selectMeetForStatus(paramMap); //只通过wordId判断会议是否存在
		if(status==null&&meeting2!=null){									//查询状态为空可能Meeting已经转变成“12”成为班后会议
												//如果Meeting存在说明已经转变成班后会议
				status="";							//赋值23说明会班前会议已经结束
			
		}
		resultMap.put("meetingState", status==null?"":status);
		resultMap.put("meetingFounder", userId);
		int id = 0;
		if(meeting2!=null){
			id = meeting2.getId();
		}
		List<Map<String,Object>> selectRecordings = recordingsMapper.selectRecordings(id,meeting);
		resultMap.put("recordingArr", selectRecordings);
		return resultMap;
	}

	@Override
	public List<Map<String, Object>> selectVisitRecordings(Integer userId,Integer meetingId,
			String meetType, Date nowTime, Date visitTime) {
		List<Map<String,Object>> visitRecordings = recordingsMapper.selectVisitRecordings(userId,meetingId, meetType, nowTime, visitTime);
		return visitRecordings;
	}

}
